//
//  ZKViewController.m
//  ZAKER
//
//  Created by Anyfish002 on 16/2/16.
//  Copyright © 2016年 yaohongchao. All rights reserved.
//

#import "ZKViewController.h"
#import "AppDelegate.h"
#import "UINavigationController+ZK.h"

@interface ZKViewController ()
@property(nonatomic,assign) BOOL isTopVC;
@end

@implementation ZKViewController

-(instancetype)init{
    self = [super init];
    self.hidesBottomBarWhenPushed = YES;
    self.extendedLayoutIncludesOpaqueBars = YES;
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UINavigationBar appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    UIImage *img=[UIImage imageWithColor:[UIColor zkColor]];
    [self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
    [self.view setBackgroundColor:[UIColor bgColor]];
    
    WS(weakSelf);
    MMDrawerController *drawerController = (MMDrawerController*)[UIApplication sharedApplication].keyWindow.rootViewController;
    UITabBarController *tabVC = (UITabBarController*)drawerController.centerViewController;
    NSString *curClassName = [NSString stringWithUTF8String:object_getClassName(self)];
    for (UINavigationController *vc in tabVC.viewControllers) {
        NSString *className = [NSString stringWithUTF8String:object_getClassName([vc.viewControllers firstObject])];
        if([curClassName isEqualToString:className]){
            self.isTopVC = YES;
        }
    }
    if(!self.isTopVC){
        [self.navigationItem setLeftItem:@[@"返回"] imageNamed:@[@"addRootBlock_toolbar_return"] block:^(NSInteger itemIndex) {
            if(itemIndex == 0) [weakSelf.navigationController popToRootViewControllerAnimated:YES];
        }];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setHidden:NO];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if(self.isTopVC || [[NSString stringWithUTF8String:object_getClassName(self)] isEqualToString:@"ZKVCAboutMe"]){
        [appDelegate.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeBezelPanningCenterView];
        [appDelegate.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModePanningCenterView];
    }else{
        [appDelegate.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
        [appDelegate.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
